package com.ruoyi.web.controller.express;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.express.domain.ExpressInfo;
import com.ruoyi.express.service.IExpressInfoService;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.system.domain.SysUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 快递  信息操作处理
 *
 * @author ruoyi
 * @date 2018-12-27
 */
@Controller
@RequestMapping("/express/expressInfo")
@Api(tags = "快递管理接口")
public class ExpressInfoController extends BaseController {
    private String prefix = "express/expressInfo";

    @Autowired
    private IExpressInfoService expressInfoService;

    @ApiOperation("to快递管理页面")
    @RequiresPermissions("express:expressInfo:view")
    @GetMapping()
    public String expressInfo() {
        return prefix + "/expressInfo";
    }

    /**
     * 查询快递 列表
     */
    @ApiOperation("快递列表")
    @RequiresPermissions("express:expressInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ExpressInfo expressInfo) {
        startPage();
        List<ExpressInfo> list = expressInfoService.selectExpressInfoList(expressInfo);
        return getDataTable(list);
    }


    /**
     * 导出快递 列表
     */
    @ApiOperation("导出快递列表")
    @RequiresPermissions("express:expressInfo:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ExpressInfo expressInfo) {
        List<ExpressInfo> list = expressInfoService.selectExpressInfoList(expressInfo);
        ExcelUtil<ExpressInfo> util = new ExcelUtil<ExpressInfo>(ExpressInfo.class);
        return util.exportExcel(list, "expressInfo");
    }

    /**
     * 新增快递
     */
    @ApiOperation("to新增快递信息页面")
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存快递
     */
    @ApiOperation("新增快递信息")
    @RequiresPermissions("express:expressInfo:add")
    @Log(title = "快递 ", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ExpressInfo expressInfo) {
        SysUser sysUser = ShiroUtils.getSysUser();
        expressInfo.setUserId(sysUser.getUserId());
        expressInfo.setDeptId(sysUser.getDeptId());
        expressInfo.setCreateBy(sysUser.getUserId().toString() + "-" + sysUser.getUserName());
        expressInfo.setCreateTime(new Date());
        return toAjax(expressInfoService.insertExpressInfo(expressInfo));
    }

    /**
     * 修改快递
     */
    @ApiOperation("to修改快递信息页面")
    @GetMapping("/edit/{expressId}")
    public String edit(@PathVariable("expressId") Integer expressId, ModelMap mmap) {
        ExpressInfo expressInfo = expressInfoService.selectExpressInfoById(expressId);
        mmap.put("expressInfo", expressInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存快递
     */
    @ApiOperation("修改快递信息")
    @RequiresPermissions("express:expressInfo:edit")
    @Log(title = "快递 ", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ExpressInfo expressInfo) {
        SysUser sysUser = ShiroUtils.getSysUser();
        expressInfo.setUpdateBy(sysUser.getUserId().toString() + "-" + sysUser.getUserName());
        expressInfo.setUpdateTime(new Date());
        return toAjax(expressInfoService.updateExpressInfo(expressInfo));
    }

    /**
     * 删除快递
     */
    @ApiOperation("删除快递信息")
    @ApiImplicitParam(name = "ids", value = "快递id列表", dataType = "String")
    @RequiresPermissions("express:expressInfo:remove")
    @Log(title = "快递 ", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(expressInfoService.deleteExpressInfoByIds(ids));
    }

}
